import { Component, Prop } from 'vue-facing-decorator'
import toNative from '@/utils/toNative'
import TableRender, { type TableRenderColumnTypes } from '@/render/TableRender'
import type { AnyObject } from '@/types'
import { getDailyInsurancePlanList } from '@/api/insurance/daily'
import type { GroupInfoDto, WesureInfoDto } from '@/api/company/types'
import type { DailyPlanDto } from '@/api/insurance/daily/types'
import dayjs from 'dayjs'

@Component
export class OpenPlans extends TableRender {
    @Prop() dailyInfo!: WesureInfoDto
    tableColumnConfigOld = () => [
        {
            field: 'insurCompanyName',
            title: '保险公司',
        },
        {
            field: 'planName',
            title: '方案简称',
        },
        {
            field: 'createTime',
            title: '开通时间',
            formatter: ({row}) => {
                return dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss')
            }
        },
    ] as TableRenderColumnTypes<DailyPlanDto>

    onLoadData(pageNum: number, pageSize: number, filters: AnyObject) {
        if (!this.dailyInfo.companyId) return []
        return getDailyInsurancePlanList({
            companyId: this.dailyInfo?.companyId,
            pageSize,
            pageNum
        })
    }

    render() {
        return <>{super.renderTable()}</>
    }
}

export default toNative<{dailyInfo: WesureInfoDto | GroupInfoDto}, {}>(OpenPlans)